package com.fusion.core.crypto.cryptolayers;

import com.fusion.core.CoreSubsystem;
import com.fusion.core.comm.Connection;

import java.nio.ByteBuffer;

/**
 *
 * Simple encryption layer used for testing
 *
 *
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 11, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class TranslationCryptoLayer extends BufferedCryptoLayer {
    public TranslationCryptoLayer(CoreSubsystem core) {
        super(core);
        if(com.fusion.core.crypto.T.t) T.info("Starting TranslationCryptoLayer");
    }

    public int encrypt(Connection c, ByteBuffer src, ByteBuffer dst) {
        int start = dst.position();
        dst.put(src);
        int end = dst.position();
        if(T.t)T.ass(dst.hasArray(), "No array!");
        byte arr[] = dst.array();
        for(int i=start;i<end;i++) arr[i] = arr[i] += 33;
        return end-start;

    }

    public void decrypt(Connection c, ByteBuffer src, ByteBuffer dst) {
        int start = dst.position();
        dst.put(src);
        int end = dst.position();
        if(T.t)T.ass(dst.hasArray(), "No array!");
        byte arr[] = dst.array();
        for(int i=start;i<end;i++) arr[i] = arr[i] -= 33;
    }
}
